package cn.ly.sort.bubble;

public class ArrayBub {
	
	private long[] a;
	private int nElems;
	
	public ArrayBub(int size){
		a = new long[size];
		this.nElems = 0;
	}
	
	public void insert(long value){
		a[this.nElems] = value;
		this.nElems++;
	}
	
	public void display(){
		for(int i=0; i < this.nElems; i++){
			System.out.print(a[i] + " ");
		}
		System.out.println();
	}
	
	public void bubbleSort(){//时间负载度    O(n的2次方)
		for(int i=this.nElems-1; i > 1; i--){
			for(int j=0; j < i; j++){
				if(a[j] > a[j+1]){
					swap(j,j+1);
				}
			}
			
		}
	}
	
	
	private void swap(int one,int two){
		a[one] = a[one]^a[two];
		a[two] = a[one]^a[two];
		a[one] = a[one]^a[two];
		
		/*long temp = 0;
		temp = a[one];
		a[one] = a[two];
		a[two] = temp;*/
	}
}
